(define (render-a a-text a-a)
  (local [(define attributes (html:html-element-attributes a-a))
          (define Contents-of-a (html:html-full-content a-a))
          (define initpos (send a-text get-start-position))
          (define (finalpos) (send a-text get-start-position))
          (define href (get-attribute-value attributes 'href ""))
          (define a-url (if (and (string-ci=? "file" (url-scheme base-path))
                                 (> (string-length href) 0)
                                 (char=? #\# (string-ref href 0)))
                            base-path
                            (combine-url/relative base-path href)))
          (define name (get-attribute-value attributes 'name ""))
          (define (open-url a-text start end)
            (local [(define scheme (url-scheme a-url))
                    (define target-location (if (> (string-length href) 0)
                                                (get-anchor-location (substring href 1 (string-length href)))
                                                #f))]
              (cond [(and (boolean? scheme)
                          (boolean? target-location))
                     (void)]
                    [(and (equal? base-path a-url)
                          (char=? #\# (string-ref href 0)))
                     (if (boolean? target-location)
                         (void)
                         (send a-text scroll-to-position target-location #f (+ (send a-text last-position) target-location) 'start))]
                    [(and (string-ci=? "file" (url-scheme a-url))
                          (char=? #\# (string-ref href 0)))
                     (send a-text erase)
                     (set! base-path a-url)
                     (set! local-anchors empty)
                     (render-html a-text (call/input-url a-url get-pure-port html:read-html))
                     (set! target-location (get-anchor-location (substring href 1 (string-length href))))
                     (if (boolean? target-location)
                         (void)
                         (send a-text scroll-to-position target-location #f (+ (send a-text last-position) target-location) 'start))]
                    [else
                     (send a-text erase)
                     (set! base-path a-url)
                     (set! local-anchors empty)
                     (render-html a-text (call/input-url a-url get-pure-port html:read-html))
                     (set! target-location (get-anchor-location (url-fragment a-url)))
                     (if (boolean? target-location)
                         (void)
                         (send a-text scroll-to-position target-location #f (+ (send a-text last-position) target-location) 'start))])))
          (define (colorize-anchor)
            (cond [(and (boolean? (url-scheme a-url))
                        (boolean? (url-fragment a-url))) (void)]
                  [else            
                   (underline a-text initpos (finalpos))
                   (changefontcolor a-text "blue" initpos (finalpos))]))]
    (cond [(<= (string-length href) 0)
           (put-anchor! name initpos)
           (for-each (lambda (a)
                       (render-Contents-of-a a-text a))
                     Contents-of-a)]
          [else
           (put-anchor! name initpos)
           (for-each (lambda (a)
                       (render-Contents-of-a a-text a))
                     Contents-of-a)
           (send a-text set-clickback initpos (finalpos) open-url #f #f)
           (colorize-anchor)])))